using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace MacViet.DataBaseAPI
{
    /// <summary>
    /// Description: Concrete DataProvider for table Services_Categories. Provides atomic API functions.
    /// Author:  phong.huynh
    /// Created: 13/08/2010 10:24:28 SA
    /// </summary>
    public class SERVICE_CATEGROIESDataAPI
    {
        private SQLHelper _dbTool = new SQLHelper();


        // ************************************
        // Implements function getByColumnName
        // ************************************

        public DataTable getBySERCAT_ID(System.Int32 SERCAT_ID, System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICE_CATEGROIESDTO._ACC_ID, ACC_ID),
                                      new SqlParameter(SERVICE_CATEGROIESDTO._SERCAT_ID, SERCAT_ID) };
            return _dbTool.executeReader("SP_SEL_SERVICE_CATEGROIES_getBySERCAT_ID", parm);
        }


        public DataTable getBySERCATE_ID(System.Int32 SERCATE_ID)
                {
                    SqlParameter[] parm = { new SqlParameter(SERVICE_CATEGROIESDTO._SERCAT_ID, SERCATE_ID) };
                    return _dbTool.executeReader("SP_GET_CATE_ID", parm);
                }

        public DataTable getByACC_ID(System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICE_CATEGROIESDTO._ACC_ID, ACC_ID) };
            return _dbTool.executeReader("SP_SEL_SERVICE_CATEGROIES_getByACC_ID", parm);
        }

        // *************************************************
        // Implement function getAll/getByDynamicCondition
        // *************************************************

        public DataTable getAll()
        {
            return _dbTool.executeReader("SP_SEL_SERVICE_CATEGROIES_getAll");
        }

        public DataTable getAllByAcc_ID(System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICE_CATEGROIESDTO._ACC_ID, ACC_ID) };
            return _dbTool.executeReader("SP_SEL_getAll_SERVICE_CATEGROIES", parm);
        }

        // ********************************************************
        // Implement function getByPrimaryKeys / getByForeignKeys
        // In case table have composite primary/foreign keys
        // ********************************************************

        public DataTable getByPrimaryKeys(System.Int32 SERCAT_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICE_CATEGROIESDTO._SERCAT_ID, SERCAT_ID) };
            return _dbTool.executeReader("SP_SEL_SERVICE_CATEGROIES_getByPrimaryKeys", parm);
        }

        public void InsertIntoSerCat(System.String SERCAT_NAME,System.Int32 ACC_ID)
        {
            SqlParameter[] parm = {  new SqlParameter(SERVICE_CATEGROIESDTO._SERCAT_NAME,SERCAT_NAME),
                                  new SqlParameter(SERVICE_CATEGROIESDTO._ACC_ID,ACC_ID)};
            int effectedRows = _dbTool.ExecuteNoneQuery("SP_INSERT_INTO_SERVICE_CATEGROIES", parm);


            //return (effectedRows == 1);
        }

         public void updateSERVICE_CATEGROIES(System.Int32 SERCAT_ID, System.String SERCAT_NAME,System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICE_CATEGROIESDTO._SERCAT_ID,SERCAT_ID),                                   
                                    new SqlParameter(SERVICE_CATEGROIESDTO._SERCAT_NAME,SERCAT_NAME),
                                  new SqlParameter(SERVICE_CATEGROIESDTO._ACC_ID,ACC_ID)};
            int affectRows = _dbTool.ExecuteNoneQuery("SP_UDP_SERVICE_CATEGROIES_updates", parm);
        }


        // ********************************************************************************
        // Implementation of deleteAll/deteleByForeignKeys/deleteByPrimaryKeys function		
        // ********************************************************************************

        // return number of deleted rows		
        public int deleteAll()
        {
            return _dbTool.ExecuteNoneQuery("SP_DEL_SERVICE_CATEGROIES_deleteAll");
        }

        // return number of deleted rows
        public int deleteByPrimaryKeys(System.Int32 SERCAT_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICE_CATEGROIESDTO._SERCAT_ID, SERCAT_ID) };
            return _dbTool.ExecuteNoneQuery("SP_DEL_SERVICE_CATEGROIES_deleteByPrimaryKeys", parm);
        }

    }
}